package com._54programer.service.impl;

import com._54programer.dao.IAccountDao;
import com._54programer.domain.Account;
import com._54programer.service.AccountService;

public class AccountServiceImpl implements AccountService {

    private IAccountDao accountDao;

    public void setAccountDao(IAccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public Account findAccountById(Integer id) {
        return accountDao.findAccountById(id);
    }

    public Account findAccountByName(String name) {
        return accountDao.findAccountByName(name);
    }

    public void transfer(Integer sourceId, Integer targeId, Float money) {
        //1.根据名称查询两个账户
        Account source = accountDao.findAccountById(sourceId);
        Account target = accountDao.findAccountById(targeId);
        //2.修改两个账户的金额
        source.setMoney(source.getMoney()-money);//转出账户减钱
        target.setMoney(target.getMoney()+money);//转入账户加钱
        //3.更新两个账户
        accountDao.updateAccount(source);
        int i=1/0;
        accountDao.updateAccount(target);
    }
}
